/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package poproject.GUI;

import java.awt.Container;
import java.util.ArrayList;
import javax.swing.JFrame;

/**
 *
 * @author janka_000
 */
public class TimePanel extends javax.swing.JPanel {

    private MainWindow mMainWindow;         //< Zmienna reprezentująca główne okno programu
    private PTConfigWindow mConfigWindow;   //< Zmienna reprezentująca okno na którym jest wyświetlany panel
    private ArrayList<Number> mTimeList;    //< Lista danych numerycznych pochodząych z panelu
    
    /**
     * Konstruktor tworzący instancję panelu.
     * @param mainWindow Główne okno aplikacji
     * @param configWindow Okno na którym wyswietlany jest panel
     */
    public TimePanel(MainWindow mainWindow, PTConfigWindow configWindow) {
        initComponents();
        mTimeList = new ArrayList<>();
        mMainWindow = mainWindow;
        mConfigWindow = configWindow;
        this.jSpinnerGamesDayCount.setValue(4);
        this.jSpinnerGamesWeekCount.setValue(4);
    }
    
    /**
     * Długość trwania turnieju.
     * Metoda pozwalająca na dostęp do czasu trwania turnieju.
     * @return Czas trwania turnieju
     */
    public int getCompetitionDuration()
    {
        return 0;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jButtonClose = new javax.swing.JButton();
        jButtonApply = new javax.swing.JButton();
        jSpinnerGamesDayCount = new javax.swing.JSpinner();
        jSpinnerGamesWeekCount = new javax.swing.JSpinner();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setText("Ramy czasowe turnieju");

        jButtonClose.setText("Zamknij");
        jButtonClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCloseActionPerformed(evt);
            }
        });

        jButtonApply.setText("Zatwierdź");
        jButtonApply.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonApplyActionPerformed(evt);
            }
        });

        jSpinnerGamesDayCount.setModel(new javax.swing.SpinnerNumberModel(1, 1, 7, 1));
        jSpinnerGamesDayCount.setPreferredSize(new java.awt.Dimension(69, 20));

        jSpinnerGamesWeekCount.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(2), Integer.valueOf(1), null, Integer.valueOf(1)));

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel3.setText("Ilość tygodni");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel4.setText("Ilość dni rozgrywkowych na tydzień");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButtonApply, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButtonClose, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jSpinnerGamesWeekCount, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, 0)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jSpinnerGamesDayCount, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSpinnerGamesWeekCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSpinnerGamesDayCount, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonClose)
                    .addComponent(jButtonApply))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Zamknięcie aplikacji.
     * Zapisa danych wprowadzonych w panelu i przesłanie ich do głównego okna 
     * aplikacji. Zamknięcie okna edycyjnego.
     * @param evt 
     */
    private void jButtonCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCloseActionPerformed
        // TODO add your handling code here:
        mTimeList.clear();
        mTimeList.add((Integer)this.jSpinnerGamesWeekCount.getValue());
        mTimeList.add((Integer)this.jSpinnerGamesDayCount.getValue());
        mMainWindow.setTimeArray(mTimeList);
        this.mConfigWindow.setVisible(false);
    }//GEN-LAST:event_jButtonCloseActionPerformed

    /**
     * Zatwierdzenie zmian.
     * Zapisa danych wprowadzonych w panelu i przesłanie ich do głównego okna 
     * aplikacji
     * @param evt 
     */
    private void jButtonApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonApplyActionPerformed
        // TODO add your handling code here:
        mTimeList.clear();
        mTimeList.add((Integer)this.jSpinnerGamesWeekCount.getValue());
        mTimeList.add((Integer)this.jSpinnerGamesDayCount.getValue());
        mMainWindow.setTimeArray(mTimeList);
    }//GEN-LAST:event_jButtonApplyActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonApply;
    private javax.swing.JButton jButtonClose;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JSpinner jSpinnerGamesDayCount;
    private javax.swing.JSpinner jSpinnerGamesWeekCount;
    // End of variables declaration//GEN-END:variables
}
